package com.ryudo.mh.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ryudo.mh.model.Meeting;
import com.ryudo.mh.service.MeetingService;

@Controller
public class MeetingController {

	@Autowired
	MeetingService meetingService;
	
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String listMeetings(Model model) {
		
		List<Meeting> meetings = meetingService.findAllMeetings();
		model.addAttribute("meetings", meetings);
		
		return "/meeting/list";
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String addMeetingPage(Model model) {
		model.addAttribute("meeting", new Meeting());
		return "/meeting/add";
	}

	@RequestMapping(value = "/addMeeting", method = RequestMethod.POST)
	public @ResponseBody Meeting addMeeting(@ModelAttribute("meeting") Meeting meeting) {
		Meeting result = meetingService.save(meeting);
		return result;
	}

}
